/**
 * 
 */
package co.fitstart.payment.entity.transaction;

/**
 * @author lute
 *
 */
public enum TransactionStatus {

    /** 已创建支付记录 */
    CREATED(0, OperationType.CREATE),
    
    /** 已支付 */
    PAID(1, OperationType.PAY),
    
    /** 部分退款 */
    PARTIAL_REFUNDED(2, OperationType.REFUND),
    
    /** 全额退款 */
    REFUNDED(3, OperationType.REFUND);
    
    private int code;
    
    private OperationType operationType;
    
    /**
     * @param code
     * @param operationType
     */
    private TransactionStatus(int code, OperationType operationType) {
        this.code = code;
        this.operationType = operationType;
    }
    
    /**
     * @return the code
     */
    public int getCode() {
        return code;
    }
    
    /**
     * @return the operationType
     */
    public OperationType getOperationType() {
        return operationType;
    }
    
    /**
     * Determine whether transaction record status is the CREATED status
     * 
     * @return
     */
    public boolean isCreated() {
        return this.code == TransactionStatus.CREATED.getCode();
    }
    
    /**
     * 
     * @return
     */
    public boolean isPaid() {
        return this.code == TransactionStatus.PAID.getCode();
    }
    
    /**
     * Get transaction record status from code
     * 
     * @param code
     * @return
     */
    public static TransactionStatus codeOf(int code) {
        for(TransactionStatus status : TransactionStatus.values()) {
            if(status.getCode() == code) {
                return status;
            }
        }
        return null;
    }

}
